package com.connection.second.wallpaper.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.connection.second.common.utils.DateUtils;
import com.connection.second.wallpaper.domain.vo.ClassifyNamesVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.connection.second.wallpaper.mapper.PaperClassifyMapper;
import com.connection.second.wallpaper.domain.entity.PaperClassify;
import com.connection.second.wallpaper.service.IPaperClassifyService;

/**
 * 分类管理Service业务层处理
 * 
 * @author FL
 * @date 2024-11-12
 */
@Service
public class PaperClassifyServiceImpl implements IPaperClassifyService 
{
    @Autowired
    private PaperClassifyMapper paperClassifyMapper;

    /**
     * 查询分类管理
     * 
     * @param id 分类管理主键
     * @return 分类管理
     */
    @Override
    public PaperClassify selectPaperClassifyById(Long id)
    {
        return paperClassifyMapper.selectPaperClassifyById(id);
    }

    /**
     * 查询分类管理列表
     * 
     * @param paperClassify 分类管理
     * @return 分类管理
     */
    @Override
    @Cacheable(value = "classifyListCache", key = "'selectPaperClassifyList'+#paperClassify.toString()")
    public List<PaperClassify> selectPaperClassifyList(PaperClassify paperClassify)
    {
        return paperClassifyMapper.selectPaperClassifyList(paperClassify);
    }

    /**
     * 新增分类管理
     * 
     * @param paperClassify 分类管理
     * @return 结果
     */
    @Override
    public int insertPaperClassify(PaperClassify paperClassify)
    {
        return paperClassifyMapper.insertPaperClassify(paperClassify);
    }

    /**
     * 修改分类管理
     * 
     * @param paperClassify 分类管理
     * @return 结果
     */
    @Override
    public int updatePaperClassify(PaperClassify paperClassify)
    {
        paperClassify.setUpdateTime(DateUtils.getNowDate());
        return paperClassifyMapper.updatePaperClassify(paperClassify);
    }

    /**
     * 批量删除分类管理
     * 
     * @param ids 需要删除的分类管理主键
     * @return 结果
     */
    @Override
    public int deletePaperClassifyByIds(Long[] ids)
    {
        return paperClassifyMapper.deletePaperClassifyByIds(ids);
    }

    /**
     * 删除分类管理信息
     * 
     * @param id 分类管理主键
     * @return 结果
     */
    @Override
    public int deletePaperClassifyById(Long id)
    {
        return paperClassifyMapper.deletePaperClassifyById(id);
    }

    /**
     * 查询分类名称列表
     * @return
     */
    @Override
    @Cacheable(value = "classifyNamesCache", key = "'classifyNames'+#classifyType")
    public List<ClassifyNamesVo> selectClassifyNameList(Integer classifyType) {
        PaperClassify classify = new PaperClassify();
        classify.setType(classifyType);
        List<PaperClassify> classifyList = paperClassifyMapper.selectPaperClassifyList(classify);
        if (classifyList!= null && !classifyList.isEmpty()) {
            List<ClassifyNamesVo> list = new ArrayList<>();
            for (PaperClassify paperClassify : classifyList) {
                ClassifyNamesVo namesVo = new ClassifyNamesVo();
                namesVo.setId(paperClassify.getId());
                namesVo.setName(paperClassify.getName());
                list.add(namesVo);
            }
            return list;
        }
        return null;
    }
}
